<template id="c-seckill">
    <div>
        <div class="title-bar">{{ seckillForm.title }}</div>
        <el-tabs v-model="cTitleActive">
            <el-tab-pane label="内容设置" name="first">
                <el-form ref="form" :model="seckillForm" label-width="120px" label-position="left">
                    <el-form-item label="商品数量">
                        <el-input v-model="seckillForm.num" type="number" size="small"></el-input>
                    </el-form-item>
                    <el-form-item label="是否显示名称">
                        <el-switch
                                style="float: right"
                                :active-value="1"
                                :inactive-value="2"
                                v-model="seckillForm.show_title">
                        </el-switch>
                    </el-form-item>
                    <el-form-item label="是否显示价格">
                        <el-switch
                                style="float: right"
                                :active-value="1"
                                :inactive-value="2"
                                v-model="seckillForm.show_price">
                        </el-switch>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
            <el-tab-pane label="样式设置" name="second">
                <el-form ref="form" :model="seckillForm" label-width="80px" label-position="left">
                    <el-form-item label="背景颜色">
                        <el-color-picker v-model="seckillForm.bgColor" style="float: right" size="small"></el-color-picker>
                    </el-form-item>
                    <el-form-item label="字体颜色">
                        <el-color-picker v-model="seckillForm.fontColor" style="float: right" size="small"></el-color-picker>
                    </el-form-item>
                    <el-form-item label="背景样式">
                        <el-button-group style="float: right">
                            <el-button size="mini" icon="iconfont icon-checkbox" :class="{'primary': seckillForm.bgStyle == 'square'}" @click="changeBg('square')"></el-button>
                            <el-button size="mini" icon="iconfont icon-yuanjiao" :class="{'primary': seckillForm.bgStyle == 'circle'}" @click="changeBg('circle')"></el-button>
                        </el-button-group>
                    </el-form-item>
                    <el-form-item label="背景边距">
                        <el-slider
                                v-model="seckillForm.bgMargin"
                                input-size="mini"
                                show-input>
                        </el-slider>
                    </el-form-item>
                    <el-form-item label="文本大小">
                        <el-slider
                                v-model="seckillForm.fontSize"
                                input-size="mini"
                                show-input>
                        </el-slider>
                    </el-form-item>
                    <el-form-item label="页面间距">
                        <el-slider
                                v-model="seckillForm.pageMargin"
                                input-size="mini"
                                show-input>
                        </el-slider>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
    Vue.component('seckill', {
        template: '#c-seckill',
        props: {
            comData: {
                type: Object
            }
        },
        data() {
            return {
                seckillForm: {
                    type: 'seckill',
                    title: '整点秒杀', // 标题
                    num: 3, // 数量
                    show_title: 1, // 是否显示名称
                    show_price: 1, // 是否显示价格
                    bgColor: '#fff', // 背景色
                    fontColor: '#000', // 字体颜色
                    bgStyle: 'square', // 背景样式
                    bgMargin: 0, // 背景边距
                    fontSize: 12, // 文本大小
                    pageMargin: 0 // 页面间距
                },
                cTitleActive: 'first'
            }
        },
        computed: {
            componentData() {
                return JSON.parse(JSON.stringify(this.seckillForm));
            },
        },
        watch: {
            componentData: {
                handler(newVal, oldVal) {
                    if (!oldVal) {
                        return false;
                    }

                    this.$emit('diy', {type: 'seckill', form: this.componentData, data: []})
                },
                deep: true
            },
            comData: {
                handler(newVal) {
                    this.seckillForm = newVal
                },
                deep: true
            }
        },
        created() {
            if (this.comData) {
                this.seckillForm = this.comData
            }
        },
        methods: {
            // 设置背景
            changeBg(type) {
                this.seckillForm.bgStyle = type
            }
        }
    })
</script>

<style>

</style>